<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/WEB-INF/faces/template.xhtml">
        <ui:define name="title">
            <h:outputText value="All Invoices"></h:outputText>
        </ui:define>
        <ui:define name="content">
            <p:panel header="All Invoices" style="border: none;">
                <h:form >
                    <h:panelGroup id="messagePanel" layout="block">
                        <p:growl sticky="true"/>
                    </h:panelGroup>

                    <p:treeTable  value="#{invoiceBean.invoices}" var="item" >
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Invoice #"/>
                            </f:facet>
                            <h:outputText value="#{item.type == 'invoiceItem' ? '-' : item.id }"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Consignor"/>
                            </f:facet>
                            <h:outputText value="#{item.type == 'invoiceItem' ? '-' : item.consignor.companyName }"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Consignee"/>
                            </f:facet>
                            <h:outputText value="#{item.type == 'invoiceItem' ? '-' : item.consignee.companyName }"/>
                        </p:column>                      
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="From"/>
                            </f:facet>
                            <h:outputText value="#{item.type == 'invoiceItem' ? '-' : item.shippingFrom }"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="To"/>
                            </f:facet>
                            <h:outputText value="#{item.type == 'invoiceItem' ? '-' : item.shippingTo}"/>
                        </p:column>
                       
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Date"/>
                            </f:facet>
                            <h:outputText value="#{item.type == 'invoiceItem' ? '-' : item.invoiceDate}">
                                <f:convertDateTime pattern="dd/MM/yyyy"/>
                            </h:outputText>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Item"/>
                            </f:facet>
                            <h:outputText value="#{item.type == 'invoiceItem' ? item.itemDiscription : '-'}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Count"/>
                            </f:facet>
                            <h:outputText value="#{item.type == 'invoiceItem' ? item.packageCount : '-'}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Weight"/>
                            </f:facet>
                            <h:outputText value="#{item.type == 'invoiceItem' ? item.actualWeight : '-'}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Item Bill#"/>
                            </f:facet>
                            <h:outputText value="#{item.type == 'invoiceItem' ? item.referenceNumber : '-'}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>

                            <p:commandButton  action="#{invoiceBean.prepareEdit(item.id)}"  value="Show Detail" rendered="#{item.type == 'invoice'}"/>
                        </p:column>
                    </p:treeTable>
                    <br />
                    <p:commandButton  action="pretty:addInvoice" value="New Invoice"/>

                </h:form>
            </p:panel>
        </ui:define>
    </ui:composition>
</html>